{extend name="../../../view/public/base" /}

{block name="css"}
<style>
    body {
        background-color: #F2F2F2;
    }
</style>
{/block}

{block name="body"}
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <form class="layui-form" lay-filter="addForm" autocomplete="off">
                    <!--应用名称-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">应用名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="app_name" placeholder="请输入应用名称" class="layui-input" value="{$row.app_name}">
                        </div>
                    </div>
                    <!--表名-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">表名</label>
                        <div class="layui-input-block">
                            <input type="text" name="table_name" placeholder="请输入表名" class="layui-input" value="{$row.table_name}">
                        </div>
                    </div>
                    <!--自定义控制器名-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">自定义控制器名</label>
                        <div class="layui-input-block">
                            <input type="text" name="controller_name_diy" placeholder="请输入自定义控制器名" class="layui-input" value="{$row.controller_name_diy}">
                        </div>
                    </div>
                    <!--自定义模型名-->
                    <div class="layui-form-item">
                        <label class="layui-form-label">自定义模型名</label>
                        <div class="layui-input-block">
                            <input type="text" name="model_name_diy" placeholder="请输入自定义模型名" class="layui-input" value="{$row.model_name_diy}">
                        </div>
                    </div>
                    <!--状态:1=成功,0=失败-->
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-block" id="status">
                                <select name="status" lay-verify="required">
                                    <option value="" >请选择状态</option>
                                    <option value="1" {eq name="$row.status" value="1"}selected{/eq}>成功</option>
                                    <option value="0" {eq name="$row.status" value="0"}selected{/eq}>失败</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="submitBtn">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script>
    var layer, form, bwajax, upload, $, laydate;

    layui.use(['layer', 'form', 'bwajax', 'upload', 'laydate'], function () {
        layer = layui.layer;
        form = layui.form;
        bwajax = layui.bwajax.instance();
        upload = layui.upload;
        $ = layui.jquery;
        laydate = layui.laydate;



        //TODO 监听提交按钮
        form.on('submit(submitBtn)', function (obj) {
            data = obj.field;

            if(!data.app_name) {layer.msg('应用名称不能为空', {icon: 2});return false}
            if(!data.table_name) {layer.msg('表名不能为空', {icon: 2});return false}
            if(!data.controller_name_diy) {layer.msg('自定义控制器名不能为空', {icon: 2});return false}
            if(!data.model_name_diy) {layer.msg('自定义模型名不能为空', {icon: 2});return false}
            if(!data.status) {layer.msg('状态不能为空', {icon: 2});return false}


            //TODO ajax调用后台接口
            bwajax.post("{:Url('edit')}?id={$row.id}", data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('提交成功', {icon: 1});
                        submitSuccess();
                    } else {
                        layer.msg(response.data.msg, {icon: 2});
                    }
                })

            return false;
        })
    });
</script>
{/block}